﻿namespace DeltaGroup.WheelOfJeopardy.UI.Screens
{
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Media;
    using DeltaGroup.WheelOfJeopardy.Util;


    /// <summary>
    /// Interaction logic for GameSetup.xaml
    /// </summary>
    public partial class GameSetup : UserControl
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="GameSetup"/> class.
        /// </summary>
        public GameSetup()
        {
            InitializeComponent();
        }

        #endregion Constructors

        #region Methods

        /// <summary>
        /// Determines whether this instance can start the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.CanExecuteRoutedEventArgs"/> instance containing the event data.</param>
        private void CanStart(object sender, CanExecuteRoutedEventArgs e)
        {
            var txts = from object item in itemsControl.Items
                       let cp = itemsControl.ItemContainerGenerator.ContainerFromItem(item) as ContentPresenter
                       let txt = Extensions.FindVisualChild<TextBox>(cp)
                       where txt != null
                       select txt;

            e.CanExecute = txts.Any(Validation.GetHasError) == false && Validation.GetHasError(cbFiles) == false;
            e.Handled = true;
        }

        #endregion Methods
    }
}